home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfset.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.8 KB  |  65 lines

  1. <!--- This example shows how to use CFSET --->
  2.  
  3. <CFQUERY NAME="GetMessages" DATASOURCE="cfsnippets">
  4. SELECT   *
  5. FROM     Messages
  6. </CFQUERY>
  7.  
  8. <HTML>
  9.  
  10. <HEAD>
  11. <TITLE>
  12. CFSET Example
  13. </TITLE>
  14. </HEAD>
  15.  
  16. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  17. <BODY  bgcolor="#FFFFD5">
  18.  
  19. <H3>CFSET Example</H3>
  20.  
  21. <P>CFSET allows you to set and reassign values to local or
  22. global variables within a CF template.
  23.  
  24. <CFSET NumRecords = GetMessages.RecordCount>
  25. <P>For example, the variable NumRecords has been declared on
  26. this template to hold the amount of records returned from
  27. our query (<CFOUTPUT>#NumRecords#</CFOUTPUT>).
  28.  
  29. <P>In addition, CFSET can be used to pass variables from other 
  30. pages, such as this example which takes the url parameter
  31. Test from this link (<a href="cfset.cfm?test=<CFOUTPUT>#URLEncodedFormat("
  32. hey, you, get off of my cloud")#</CFOUTPUT>">click here</A>) to display 
  33. a message: 
  34. <P><CFIF IsDefined ("url.test") is "True">
  35.     <CFOUTPUT><B><I>#url.test#</I></B></CFOUTPUT>
  36. <CFELSE>
  37.     <H3>The variable url.test has not been passed from
  38.     another page.</H3>
  39. </CFIF>
  40.  
  41. <P>Finally, CFSET can also be used to collect environmental
  42. variables, such as the time, the ip of the user, or any
  43. other function or expression possible in Cold Fusion.
  44.  
  45. <CFSET the_date = #DateFormat(Now())# & " " & #TimeFormat(Now())#>
  46. <CFSET user_ip = CGI.REMOTE_ADDR>
  47. <CFSET complex_expr = (23 MOD 12) * 3>
  48. <CFSET str_example = Reverse(Left(GetMessages.body, 35))>
  49.  
  50.  
  51. <CFOUTPUT>
  52. <UL>
  53.     <LI>The date: #the_date#
  54.     <LI>User IP Address: #user_ip#
  55.     <LI>Complex Expression ((23 MOD 12) * 3): #complex_expr#
  56.     <LI>String Manipulation (the first 35 characters of
  57.     the body of the first message in our query)
  58.     <BR><B>Reversed</B> :#str_example#
  59.     <BR><B>Normal</B>: #Reverse("#str_example#")#
  60. </UL>
  61. </CFOUTPUT>
  62. </BODY>
  63.  
  64. </HTML>       
  65.